package system

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"k8s-admin/service/system"
	"k8s-admin/utils"
)

func Login(ctx *gin.Context) {
	param := new(struct {
		Username string `json:"username" binding:"required"`
		Password string `json:"password" binding:"required"`
	})

	if err := ctx.ShouldBindJSON(&param); err != nil {
		utils.ReturnContext(ctx).Failed("失败", err.Error())
	} else {
		user, err := system.NewUserInfo().Login(param.Username, param.Password)
		if err != nil {
			fmt.Println(err)
			utils.ReturnContext(ctx).Failed("失败", err.Error())
		} else {
			utils.ReturnContext(ctx).Successful("成功", user)
		}
	}
}
